# celery的任务必须写在tasks.py的文件中，别的文件名称不识别!!!
import logging
from django.core.cache import cache
from django.core.mail import send_mail
from django.conf import settings
from mycelery.main import app

log = logging.getLogger("django")


@app.task
def send_register_active_email(to_email, ms_code):
    '''发送激活邮件'''
    # 组织邮件信息
    subject = '注册验证码'  # 邮件标题
    message = '您的验证码是：' + str(ms_code)  # 发普通格式邮件内容时使用
    from_email = settings.EMAIL_HOST_USER
    recipient_list = [to_email]

    # 发邮件，该函数为阻塞函数，只有邮件发出去之后，下面的函数才会继续执行
    send_mail(subject, message, from_email, recipient_list)
